package com.ruoyi.exam.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.exam.vo.ExamUserBankProgressVo;
import com.ruoyi.exam.service.IExamUserBankProgressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 用户题库进度Controller
 *
 * @author Tellsea
 * @date 2025-06-23
 */
@Api(tags = "用户题库进度Controller")
@RestController
@RequestMapping("/exam/userBankProgress")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ExamUserBankProgressController extends BaseController {

    private final IExamUserBankProgressService examUserBankProgressService;

    @ApiOperation("查询用户题库进度列表")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamUserBankProgressVo> list(ExamUserBankProgressVo entity) {
        return examUserBankProgressService.queryList(entity);
    }

    @ApiOperation("查询用户题库进度所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ExamUserBankProgressVo entity) {
        return AjaxResult.success("查询成功", examUserBankProgressService.queryAll(entity));
    }

    @ApiOperation("导出用户题库进度列表")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:export')")
    @Log(title = "用户题库进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamUserBankProgressVo entity) {
        List<ExamUserBankProgressVo> list = examUserBankProgressService.queryAll(entity);
        ExcelUtil<ExamUserBankProgressVo> util = new ExcelUtil<>(ExamUserBankProgressVo.class);
        util.exportExcel(response, list, "用户题库进度数据");
    }

    @ApiOperation("获取用户题库进度详细信息")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:query')")
    @GetMapping(value = "/getInfo/{progressId}")
    public AjaxResult getInfo(@PathVariable("progressId") Long progressId) {
        return AjaxResult.success("查询成功", examUserBankProgressService.queryById(progressId));
    }

    @ApiOperation("新增用户题库进度")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:add')")
    @Log(title = "用户题库进度", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ExamUserBankProgressVo entity) {
        return toAjax(examUserBankProgressService.save(entity));
    }

    @ApiOperation("修改用户题库进度")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:edit')")
    @Log(title = "用户题库进度", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ExamUserBankProgressVo entity) {
        return toAjax(examUserBankProgressService.updateById(entity));
    }

    @ApiOperation("删除用户题库进度")
    @PreAuthorize("@ss.hasPermi('exam:userBankProgress:remove')")
    @Log(title = "用户题库进度", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{progressIds}")
    public AjaxResult remove(@PathVariable Long[] progressIds) {
        return toAjax(examUserBankProgressService.removeByIds(Arrays.asList(progressIds)) ? 1 : 0);
    }
}
